#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
#include <everest/odbc/Environment.h>
#include <everest/odbc/Connection.h>
#include <everest/odbc/SQLException.h>
#include <everest/odbc/Statement.h>
#include <stdio.h>
#include <iostream>

using namespace std;
using namespace NS_EVEREST;
using namespace NS_EVEREST::odbc;


class OdbcStatementTester : public CppUnit::TestFixture
{
	CPPUNIT_TEST_SUITE(OdbcStatementTester);
	CPPUNIT_TEST(test);
	CPPUNIT_TEST_SUITE_END();

public:
	OdbcStatementTester() {

	}
	~OdbcStatementTester() {}

	void setUp(){}
	void tearDown(){}

	void test();

protected:

};

CPPUNIT_TEST_SUITE_REGISTRATION(OdbcStatementTester);

void OdbcStatementTester::test()
{
	try {
		Environment env;
		Connection  con(env);
		con.open("DSN=EVEREST;UID=shi;PWD=shiyimin");

		Statement   stm(con);

		stm.close();
		con.close();
	} catch ( const SQLException& e) {
		printf("%d, %s, %s, %s\n", e.code(), e.state(), e.message(), e.source());
		CPPUNIT_FAIL(e.message());
	} catch (const int& e) {
		printf("catch int: %d\n", e);
	}
}

int main(int argc, char **argv)
{
	CppUnit::TextUi::TestRunner runner;
	CppUnit::TestFactoryRegistry &reg = CppUnit::TestFactoryRegistry::getRegistry();
	runner.addTest(reg.makeTest());
	return !runner.run();
}
